﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.InterfaceService;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
using NPOI.OpenXmlFormats.Dml;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.Service
{
    public class BaseService : IBaseService
    {
        [Autowired]
        protected ILogger<BaseService> _logger { get; set; }
        [Autowired]
        protected SystemConfigEntity _systemConfig { get; set; }

        /// <summary>
        /// 事务
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public async Task<bool> BeginTransaction(IDbContextTransaction transaction, Func<IDbContextTransaction, bool> func)
        {
            return await Task.Run(() =>
            {
                bool IsOk = false;
                try
                {
                    if (func != null)
                        IsOk = func.Invoke(transaction);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                    IsOk = false;
                    transaction.Rollback();
                }
                return IsOk;
            });
        }
        public bool Auth(string placeType, int AreaID)
        {

            if (AreaID == -1)
            {
                if (placeType.Contains("市"))
                {
                    return true;
                }
                return false;
            }
            return true;

        }

        public bool Auth(string placeType)
        {
            if (placeType.Contains("市"))
            {
                return true;
            }
            return false;
        }

        public bool Admin(string Role)
        {
            if (Role.Contains("Admin"))
            {
                return true;
            }
            return false;
        }

        public bool IsChildAccount(int RoleID)
        {
            if (RoleID == (int)eRoleType.GeneralChild)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="area"></param>
        /// <param name="city"></param>
        /// <param name="company">管理员传过来的</param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="quarter"></param>
        /// <param name="userInfo"></param>
        /// <param name="drugDetaionViews"></param>
        /// <returns></returns>


        public async Task<IQueryable<T>> QueryPipeLineTime<T>(PipeLineParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            int pastquarter = Params.Quarter.GetPastQuarter();

            int pastyear = Params.Quarter.GetByPastQuarterYear(Params.Year);

            #region 

            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                ////by qu
                if (await drugs.Where(d => d.Quarter == Params.Quarter).AnyAsync() == false)
                {
                    drugs = drugs.Where(d => d.Quarter == pastquarter);
                }
                else
                {
                    drugs = drugs.Where(d => d.Quarter == Params.Quarter);
                }
            }
            else if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                ////by month 
                if (await drugs.Where(d => d.MonitorTime.Month == Params.Month).AnyAsync() == false)
                {
                    drugs = drugs.Where(d => d.MonitorTime.Month == Params.Month - 1);
                }
                else
                {
                    drugs = drugs.Where(d => d.MonitorTime.Month == Params.Month);
                }
            }
            return drugs;
            #endregion
        }
        public IQueryable<T> QueryPipeLineTime<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {

            //int pastquarter = Params.Quarter.GetPastQuarter();
            // int pastyear = Params.Quarter.GetByPastQuarterYear(Params.Year);
            switch (Params.Years.Length)
            {
                case 1:
                    drugs = QueryPipeLineTimeOne(Params, drugs);
                    break;
                case 2:
                    drugs = QueryPipeLineTimeTwo(Params, drugs);
                    break;
                case 3:
                    drugs = QueryPipeLineTimeThree(Params, drugs);
                    break;
                case 4:
                    drugs = QueryPipeLineTimeFour(Params, drugs);
                    break;
                case 5:
                    drugs = QueryPipeLineTimeFive(Params, drugs);
                    break;
                case 6:
                    drugs = QueryPipeLineTimeSix(Params, drugs);
                    break;
                case 7:
                    drugs = QueryPipeLineTimeSeven(Params, drugs);
                    break;
                case 8:
                    drugs = QueryPipeLineTimeEight(Params, drugs);
                    break;
                case 9:
                    drugs = QueryPipeLineTimeNine(Params, drugs);
                    break;
                case 10:
                    drugs = QueryPipeLineTimeTen(Params, drugs);
                    break;
                default:
                    break;
            }

            #region 
            return drugs;
            #endregion
        }


        /// <summary>
        /// 根据角色筛选数据
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="userInfo"></param>
        /// <param name="drugDetaionViews"></param>
        /// <returns></returns>
        public IQueryable<T> QueryPipeLineRole<T>(PipeLineParameter Params, CurrentUserInfo userInfo, IQueryable<T> drugs,bool IsCity=true) where T : IPipeRole
        {
            #region 如果是管理员可以看跨地区的数据
            if (Admin(userInfo.RoleName) == false)
            {
                drugs = drugs.Where(d => d.CompanyID == userInfo.CompanyID);
            }
            else
            {
                drugs = drugs.Where(d => d.CompanyID == Params.CompanyID);
            }
            #endregion


            #region 地区权限只能看自己区域的
            if (Auth(userInfo.PlaceTypeName, Params.AreaID) == false)
            {
                throw new Exception("runtime:你只有地区的权限无法看市区的数据请传递正确的参数!");
            }

            if (IsChildAccount(userInfo.RoleID))
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && d.AreaID == userInfo.CurrentAreaID);
            }
            else if (Params.AreaID>0)
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && Params.AreaID == d.AreaID);
            }
            else if(IsCity==true)
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && d.PlaceTypeName=="市");
            }
            else
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID);
            }
            return drugs;
            #endregion
        }

        public IQueryable<T> QueryPipeLineRoleNoCity<T>(PipeLineParameter Params, CurrentUserInfo userInfo, IQueryable<T> drugs) where T : IPipeRole
        {
            #region 如果是管理员可以看跨地区的数据
            if (Admin(userInfo.RoleName) == false)
            {
                drugs = drugs.Where(d => d.CompanyID == userInfo.CompanyID);
            }
            else
            {
                drugs = drugs.Where(d => d.CompanyID == Params.CompanyID);
            }
            #endregion


            #region 地区权限只能看自己区域的
            if (Auth(userInfo.PlaceTypeName, Params.AreaID) == false)
            {
                throw new Exception("runtime:你只有地区的权限无法看市区的数据请传递正确的参数!");
            }

            if (IsChildAccount(userInfo.RoleID))
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && d.AreaID == userInfo.CurrentAreaID);
            }
            else if (Params.AreaID > 0)
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && Params.AreaID == d.AreaID);
            }
            else
            {
                drugs = drugs.Where(d => d.CityID == Params.CityID && d.PlaceTypeName!= "市");
            }
            return drugs;
            #endregion
        }


        private IQueryable<T> QueryPipeLineTimeOne<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 1)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length ==1)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeTwo<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 2)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 2)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1])
                );
                }
            }
            return drugs; 
        }

         private IQueryable<T> QueryPipeLineTimeThree<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 3)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 3)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeFour<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 4)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 4)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeFive<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 5)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 5)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])||
                  (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4])
                );
                }
            }
            return drugs;
        }

         private IQueryable<T> QueryPipeLineTimeSix<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 6)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])||
                      (d.MonitorTime.Year == Params.Years[5] && d.Quarter == Params.Quarters[5])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 6)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])||
                  (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4])||
                  (d.MonitorTime.Year == Params.Years[5] && d.MonitorTime.Month == Params.Months[5])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeSeven<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 7)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])||
                      (d.MonitorTime.Year == Params.Years[5] && d.Quarter == Params.Quarters[6])||
                      (d.MonitorTime.Year == Params.Years[6] && d.Quarter == Params.Quarters[6])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 7)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])||
                  (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4])||
                  (d.MonitorTime.Year == Params.Years[5] && d.MonitorTime.Month == Params.Months[5])||
                  (d.MonitorTime.Year == Params.Years[6] && d.MonitorTime.Month == Params.Months[6])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeEight<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 8)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])||
                      (d.MonitorTime.Year == Params.Years[5] && d.Quarter == Params.Quarters[5])||
                      (d.MonitorTime.Year == Params.Years[6] && d.Quarter == Params.Quarters[6])||
                      (d.MonitorTime.Year == Params.Years[7] && d.Quarter == Params.Quarters[7])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 8)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])||
                  (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4])||
                  (d.MonitorTime.Year == Params.Years[5] && d.MonitorTime.Month == Params.Months[5])||
                  (d.MonitorTime.Year == Params.Years[6] && d.MonitorTime.Month == Params.Months[6])||
                  (d.MonitorTime.Year == Params.Years[7] && d.MonitorTime.Month == Params.Months[7])
                );
                }
            }
            return drugs;
        }

        private IQueryable<T> QueryPipeLineTimeNine<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 9)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])||
                      (d.MonitorTime.Year == Params.Years[5] && d.Quarter == Params.Quarters[5])||
                      (d.MonitorTime.Year == Params.Years[6] && d.Quarter == Params.Quarters[6])||
                      (d.MonitorTime.Year == Params.Years[7] && d.Quarter == Params.Quarters[7])||
                      (d.MonitorTime.Year == Params.Years[8] && d.Quarter == Params.Quarters[8])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 9)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                   (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3]) ||
                      (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4]) ||
                      (d.MonitorTime.Year == Params.Years[5] && d.MonitorTime.Month == Params.Months[5]) ||
                      (d.MonitorTime.Year == Params.Years[6] && d.MonitorTime.Month == Params.Months[6]) ||
                      (d.MonitorTime.Year == Params.Years[7] && d.MonitorTime.Month == Params.Months[7]) ||
                      (d.MonitorTime.Year == Params.Years[8] && d.MonitorTime.Month == Params.Months[8])
                );
                }
            }
            return drugs;
        }
        private IQueryable<T> QueryPipeLineTimeTen<T>(PipeLineMoreParameter Params, IQueryable<T> drugs) where T : IPipeTime
        {
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Quarter)
            {
                if (Params.Quarters.Length == 10)
                {
                    drugs = drugs.Where(d =>
                    (d.MonitorTime.Year == Params.Years[0] && d.Quarter == Params.Quarters[0]) ||
                     (d.MonitorTime.Year == Params.Years[1] && d.Quarter == Params.Quarters[1]) ||
                      (d.MonitorTime.Year == Params.Years[2] && d.Quarter == Params.Quarters[2])||
                      (d.MonitorTime.Year == Params.Years[3] && d.Quarter == Params.Quarters[3])||
                      (d.MonitorTime.Year == Params.Years[4] && d.Quarter == Params.Quarters[4])||
                      (d.MonitorTime.Year == Params.Years[5] && d.Quarter == Params.Quarters[5])||
                      (d.MonitorTime.Year == Params.Years[6] && d.Quarter == Params.Quarters[6])||
                      (d.MonitorTime.Year == Params.Years[7] && d.Quarter == Params.Quarters[7])||
                      (d.MonitorTime.Year == Params.Years[8] && d.Quarter == Params.Quarters[8])||
                      (d.MonitorTime.Year == Params.Years[9] && d.Quarter == Params.Quarters[9])
                    );
                }

            }
            if (_systemConfig.QuarterOrMonth == (int)eGroupGetDateType.Month)
            {
                if (Params.Months.Length == 10)
                {
                    drugs = drugs.Where(d =>
                (d.MonitorTime.Year == Params.Years[0] && d.MonitorTime.Month == Params.Months[0]) ||
                 (d.MonitorTime.Year == Params.Years[1] && d.MonitorTime.Month == Params.Months[1]) ||
                  (d.MonitorTime.Year == Params.Years[2] && d.MonitorTime.Month == Params.Months[2])||
                  (d.MonitorTime.Year == Params.Years[3] && d.MonitorTime.Month == Params.Months[3])||
                  (d.MonitorTime.Year == Params.Years[4] && d.MonitorTime.Month == Params.Months[4])||
                  (d.MonitorTime.Year == Params.Years[5] && d.MonitorTime.Month == Params.Months[5])||
                  (d.MonitorTime.Year == Params.Years[6] && d.MonitorTime.Month == Params.Months[6])||
                  (d.MonitorTime.Year == Params.Years[7] && d.MonitorTime.Month == Params.Months[7])||
                  (d.MonitorTime.Year == Params.Years[8] && d.MonitorTime.Month == Params.Months[8])||
                  (d.MonitorTime.Year == Params.Years[9] && d.MonitorTime.Month == Params.Months[9])

                );
                }
            }
            return drugs;
        }

        /// <summary>
        /// 执行成功返回消息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public BaseMessage Ok200(string msg)
        {
            return new BaseMessage(msg,200,true);
        }

        /// <summary>
        /// 单条数据返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        public DataMessage Ok200(string msg,object Data)
        {
            return new DataMessage(msg,200,true,Data);
        }
        /// <summary>
        /// 集合数据返回
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="msg"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        public DataMessage<T> Ok200<T>(string msg, PageList<T> Data)
        {
            return new DataMessage<T>(msg, 200, true, Data);
        }
        /// <summary>
        /// 执行失败返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        public BaseMessage BadRequest400(string msg)
        {
            return new BaseMessage(msg, 400, false);
        }

        /// <summary>
        /// 执行失败返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        public DataMessage BadRequest400(string msg,object data)
        {
            return new DataMessage(msg, 400, false,data);
        }
        public DataMessage<T> BadRequest400<T>(string msg, PageList<T> data)
        {
            return new DataMessage<T>(msg, 400, false, data);
        }

        protected async Task SaveFile(IFormFile file, string dic, string fileName, Func<string, bool> func)
        {
            string extension = Path.GetExtension(file.FileName);
            if (func != null && func.Invoke(extension) == false)
            {
                return;
            }
            if (System.IO.Directory.Exists(dic) == false)
            {
                System.IO.Directory.CreateDirectory(dic);
            }
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Path.GetRandomFileName();
            }
            string outfile = Path.GetFileNameWithoutExtension(fileName) + extension;
            var filePath = Path.Combine(dic, outfile);

            if (System.IO.File.Exists(filePath))
            {
                return;
            }
            using (var stream = System.IO.File.Create(filePath))
            {
                await file.CopyToAsync(stream);
            }
        }
    }
}
